﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.DataAccessLayer;
using CuaHangMayTinh.BusinessEntities;
using System.Data;
using CuaHangMayTinh.Utilities;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// 
    /// </summary>
    public class BanHangManager
    {
        private static BanHangDA adapter = null;

        static BanHangManager()
        {
            if (adapter == null)
                adapter = new BanHangDA();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int Insert(BanHangEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int InsertTS(BanHangEntity entity)
        {
            try
            {
                return adapter.InsertTS(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int InsertTS(BanHangEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.InsertTS(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(BanHangEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMaHDMax()
        {
            try
            {
                return adapter.GetMaHDMax();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable GetInfoHoaDon()
        {
            try
            {
                return adapter.GetInfoHoaDon();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable ThongKe_BanHangModel()
        {
            try
            {
                return adapter.ThongKe_BanHangModel();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static BanHangEntity GetAllInfo_ID(int mabanhang)
        {
            try
            {
                return adapter.GetAllInfo_ID(mabanhang);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<BanHangEntity> ConvertToList( DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }
    }
}
